/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-04-23 13:34:36
 * @LastEditTime : 2023-06-21 16:02:16
 * @LastEditors  : NaN 353362604@qq.com
 * @FilePath     : \AdminStration\src\Pages\Admin\PageType\Home.jsx
 * @Description  :
 */
import '../Scss/Home.scss'
import { useRequest } from 'ahooks'
import { useEffect, useState } from 'react'
import { Http } from '../../../Common/Api'
import { TemplateData } from '../../../Common/Router/MenuNav/DiyList/WebHomeSetUp'

import { project } from '../../../Common/Data'
const { imageUrl, client_id } = project[window.location.hostname]

const ImageA01List = ['yangpu', 'nongken', 'jtgj']
const Home = () => {
    const { runAsync } = useRequest(Http, { manual: true })
    const [HomeData, setHomeData] = useState()

    useEffect(() => {
        if (!ImageA01List.includes(client_id)) {
            const [uuid] = Object.keys(JSON.parse(localStorage.getItem('ClientData')).project)
            runAsync({ url: 'getJsonInfoByUuid', data: { uuid: `home${uuid}` } }).then(res => setHomeData(res))
        }
    }, [runAsync])

    if (ImageA01List.includes(client_id)) {
        return <img className="YangpuHomeAdminBack" src={imageUrl + 'N_Admin01.png'} alt="" />
    } else {
        return (
            <div className="HomeAdmin">
                {HomeData &&
                    HomeData.map(({ i, w, h, x, y }) => {
                        const Template = TemplateData[i]
                        const style = { gridArea: `${y + 1} / ${x + 1} / ${y + h + 1} / ${w + x + 1}` }
                        return (
                            <div key={i} style={style}>
                                <Template />
                            </div>
                        )
                    })}
            </div>
        )
    }
}

export default Home
